import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;

public class ClientDetails extends HttpServlet
{
 public void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException ,IOException
 {
  
try
{ 
 PrintWriter pw=resp.getWriter();
resp.setContentType("text/html");
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con =   DriverManager.getConnection("jdbc:odbc:psi","psi","psi");
  System.out.println("connection is created"+con);
  String cid=req.getParameter("cid");
int i=Integer.parseInt(cid);

  String cname=req.getParameter("cname");
  String cloc=req.getParameter("cloc"); 
String pcode=req.getParameter("pcode");
int j=Integer.parseInt(pcode);



String submit=req.getParameter("vittu");
System.out.println("submit value"+submit);
  Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
if(submit.equals("Save"))
  	{
   PreparedStatement pstmt2=con.prepareStatement("insert into client  values(?,?,?,?)");
                System.out.println("preparestatment is created"+pstmt2);
    	pstmt2.setInt(1,i);
    	pstmt2.setString(2,cname);
                  pstmt2.setString(3,cloc);
   	 pstmt2.setInt(4,j);
                  
        
      int v=pstmt2.executeUpdate();
  if (v>0)
{
pw.println("<h1>succssfully inserted</h1>");
resp.setHeader("REFRESH","2;URL=./assign-details.htm");
 }     
}   


}
catch(Exception e)
{
 e.printStackTrace();
 }
}
 }